﻿using SIPPaser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SIPForm
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        SIPPaserServer _sipPaserServer;
        private void MainForm_Load(object sender, EventArgs e)
        {
            //导入文件
            _sipPaserServer = new SIPPaserServer();
            this.SetChart();
        }
        private void SetChart()
        {
            var name = new string[] { "注册", "呼叫" };
            var values = new int[] { 3, 10 };
            var colors = new Color[] { Color.Red, Color.Blue };
            this.ucPieChart1.SetDataSource(name, values, colors);
            this.ucPieChart1.IsRenderPercent = true;
        }
        private void toolStripButtonImport_Click(object sender, EventArgs e)
        {
            //TestSIPListView();
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
            openFileDialog.Filter = "文本文件|*.txt";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                
                _sipPaserServer.ImportSIPTxt(openFileDialog.FileName);
                RefreshSIPListView();
            }
        }
        private void RefreshSIPListView()
        {
            this.listView1.Items.Clear();
            int i = 0;
            foreach(var sipmsg in this._sipPaserServer.SIPList)
            {
                i++;
                ListViewItem li = new ListViewItem();
                li.Text = i.ToString();
                li.SubItems.Add(sipmsg.Time.ToString("yyyy-MM-dd HH:mm:ss  fff"));
                //if(sipmsg.MessageType == SIPPaser.Mod.SIPMessageType.REPLAY)
                //    li.SubItems.Add(sipmsg.StatusCode.ToString());
                //else
                //    li.SubItems.Add(sipmsg.MessageType.ToString());
                li.SubItems.Add(sipmsg.GetDisplayType());


                li.SubItems.Add(sipmsg.ToString());
                listView1.Items.Add(li);
            }
        }
        private void TestSIPListView()
        {
            this.listView1.Items.Clear();


            for (int i = 0; i < 10; i++)
            {
                ListViewItem li = new ListViewItem();
                li.Text = (i + 1).ToString();
                li.SubItems.Add("2022-5-6");
                li.SubItems.Add("SUBSCRIBE");
                li.SubItems.Add("1231321");
                listView1.Items.Add(li);
            }
        }

        private void toolStripButtonStat_Click(object sender, EventArgs e)
        {
            _sipPaserServer.GroupByCALLID();
        }
    }
}
